<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;mv命令是move的缩写，可以用来移动文件或者将文件改名（move (rename) files），是Linux系统下常用的命令，经常用来备份文件或者目录。 1．命令格式：1mv [选项] [源文件或目录] [目标文件或目录] 2．命令功能：&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- mv">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/8. Linux 命令- mv/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;mv命令是move的缩写，可以用来移动文件或者将文件改名（move (rename) files），是Linux系统下常用的命令，经常用来备份文件或者目录。 1．命令格式：1mv [选项] [源文件或目录] [目标文件或目录] 2．命令功能：&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:33:08.140Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- mv">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;mv命令是move的缩写，可以用来移动文件或者将文件改名（move (rename) files），是Linux系统下常用的命令，经常用来备份文件或者目录。 1．命令格式：1mv [选项] [源文件或目录] [目标文件或目录] 2．命令功能：&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/8. Linux 命令- mv/"/>





  <title>Linux 命令- mv | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/8. Linux 命令- mv/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- mv</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mv命令是move的缩写，可以用来移动文件或者将文件改名（move (rename) files），是Linux系统下常用的命令，经常用来备份文件或者目录。</p>
<h2 id="1．命令格式："><a href="#1．命令格式：" class="headerlink" title="1．命令格式："></a>1．命令格式：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv [选项] [源文件或目录] [目标文件或目录]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能："><a href="#2．命令功能：" class="headerlink" title="2．命令功能："></a>2．命令功能：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;视mv命令中第二个参数类型的不同（是目标文件还是目标目录），mv命令将文件重命名或将其移至一个新的目录中。当第二个参数类型是文件时，mv命令完成文件重命名，此时，源文件只能有一个（也可以是源目录名），它将所给的源文件或目录重命名为给定的目标文件名。当第二个参数是已存在的目录名称时，源文件或目录参数可以有多个，mv命令将各参数指定的源文件均移至目标目录中。在跨文件系统移动文件时，mv先拷贝，再将原有文件删除，而链至该文件的链接也将丢失。</p>
<h2 id="3．命令参数："><a href="#3．命令参数：" class="headerlink" title="3．命令参数："></a>3．命令参数：</h2><ul>
<li>-b ：若需覆盖文件，则覆盖前先行备份。  </li>
<li>-f ：force 强制的意思，如果目标文件已经存在，不会询问而直接覆盖；</li>
<li>-i ：若目标文件 (destination) 已经存在时，就会询问是否覆盖！</li>
<li>-u ：若目标文件已经存在，且 source 比较新，才会更新(update)  </li>
<li>-t  ： –target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY，即指定mv的目标目录，该选项适用于移动多个源文件到一个目录的情况，此时目标目录在前，源文件在后。     </li>
</ul>
<h2 id="4．命令实例："><a href="#4．命令实例：" class="headerlink" title="4．命令实例："></a>4．命令实例：</h2><h3 id="实例1：文件改名"><a href="#实例1：文件改名" class="headerlink" title="实例1：文件改名"></a>实例1：文件改名</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv test.log test1.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 20drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 2 root root 4096 10-25 17:46 test3</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test4</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">-rw-r--r-- 1 root root   16 10-28 06:04 test.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># mv test.log test1.txt</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 20drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">-rw-r--r-- 1 root root   16 10-28 06:04 test1.txt</div><div class="line">drwxrwxrwx 2 root root 4096 10-25 17:46 test3</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test4</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将文件test.log重命名为test1.txt     </p>
<h3 id="实例2：移动文件"><a href="#实例2：移动文件" class="headerlink" title="实例2：移动文件"></a>实例2：移动文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv test1.txt test3</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 20drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxrwxrwx 2 root root 4096 10-25 17:46 test3</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test4</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># mv test1.txt test3</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 16drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 2 root root 4096 10-28 06:09 test3</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test4</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 4</div><div class="line">-rw-r--r-- 1 root root 29 10-28 06:05 test1.txt</div><div class="line">[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将test1.txt文件移到目录test3中    </p>
<h3 id="实例3：将文件log1-txt-log2-txt-log3-txt移动到目录test3中。"><a href="#实例3：将文件log1-txt-log2-txt-log3-txt移动到目录test3中。" class="headerlink" title="实例3：将文件log1.txt,log2.txt,log3.txt移动到目录test3中。"></a>实例3：将文件log1.txt,log2.txt,log3.txt移动到目录test3中。</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mv log1.txt log2.txt log3.txt test3</div><div class="line">mv -t /opt/soft/<span class="built_in">test</span>/test4/ log1.txt log2.txt 	log3.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 28</div><div class="line">-rw-r--r-- 1 root root    8 10-28 06:15 log1.txt</div><div class="line">-rw-r--r-- 1 root root   12 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log3.txt</div><div class="line">drwxrwxrwx 2 root root 4096 10-28 06:09 test3</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># mv log1.txt log2.txt log3.txt test3</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 16drwxrwxrwx 2 root root 4096 10-28 06:18 test3</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3/</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 16</div><div class="line">-rw-r--r-- 1 root root  8 10-28 06:15 log1.txt</div><div class="line">-rw-r--r-- 1 root root 12 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt</div><div class="line">-rw-r--r-- 1 root root 29 10-28 06:05 test1.txt</div><div class="line">[root@localhost test3]<span class="comment">#</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 20</div><div class="line">-rw-r--r-- 1 root root    8 10-28 06:15 log1.txt</div><div class="line">-rw-r--r-- 1 root root   12 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log3.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">[root@localhost test3]<span class="comment"># mv -t /opt/soft/test/test4/ log1.txt log2.txt 	log3.txt </span></div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4/</span></div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 12</div><div class="line">-rw-r--r-- 1 root root  8 10-28 06:15 log1.txt</div><div class="line">-rw-r--r-- 1 root root 12 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt</div><div class="line">[root@localhost test4]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mv log1.txt log2.txt log3.txt test3 命令将log1.txt ，log2.txt， log3.txt 三个文件移到 test3目录中去，mv -t /opt/soft/test/test4/ log1.txt log2.txt log3.txt 命令又将三个文件移动到test4目录中去      </p>
<h3 id="实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖"><a href="#实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖" class="headerlink" title="实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖"></a>实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv -i log1.txt log2.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 12</div><div class="line">-rw-r--r-- 1 root root  8 10-28 06:15 log1.txt</div><div class="line">-rw-r--r-- 1 root root 12 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt</div><div class="line">[root@localhost test4]<span class="comment"># cat log1.txt </span></div><div class="line">odfdfs</div><div class="line">[root@localhost test4]<span class="comment"># cat log2.txt </span></div><div class="line">ererwerwer</div><div class="line">[root@localhost test4]<span class="comment"># mv -i log1.txt log2.txt </span></div><div class="line">mv：是否覆盖“log2.txt”? y</div><div class="line">[root@localhost test4]<span class="comment"># cat log2.txt </span></div><div class="line">odfdfs</div><div class="line">[root@localhost test4]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉"><a href="#实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉" class="headerlink" title="实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉"></a>实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv -f log3.txt log2.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 8</div><div class="line">-rw-r--r-- 1 root root  8 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt</div><div class="line">[root@localhost test4]<span class="comment"># cat log2.txt </span></div><div class="line">odfdfs</div><div class="line">[root@localhost test4]<span class="comment"># cat log3</span></div><div class="line">cat: log3: 没有那个文件或目录</div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 8</div><div class="line">-rw-r--r-- 1 root root  8 10-28 06:15 log2.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt</div><div class="line">[root@localhost test4]<span class="comment"># cat log2.txt </span></div><div class="line">odfdfs</div><div class="line">[root@localhost test4]<span class="comment"># cat log3.txt </span></div><div class="line">dfosdfsdfdss</div><div class="line">[root@localhost test4]<span class="comment"># mv -f log3.txt log2.txt </span></div><div class="line">[root@localhost test4]<span class="comment"># cat log2.txt </span></div><div class="line">dfosdfsdfdss</div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 4</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log2.txt</div><div class="line">[root@localhost test4]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;log3.txt的内容直接覆盖了log2.txt内容，-f 这是个危险的选项，使用的时候一定要保持头脑清晰，一般情况下最好不用加上它。        </p>
<h3 id="实例6：目录的移动"><a href="#实例6：目录的移动" class="headerlink" title="实例6：目录的移动"></a>实例6：目录的移动</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv dir1 dir2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log2.txt</div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log2.txt</div><div class="line">[root@localhost test4]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 3 root root 4096 10-28 06:24 test3</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:48 test4</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># mv test4 test3</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 4 root root 4096 10-28 06:54 test3</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3/</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:48 test4</div><div class="line">[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果目录dir2不存在，将目录dir1改名为dir2；否则，将dir1移动到dir2中。  </p>
<h3 id="实例7：移动当前文件夹下的所有文件到上一级目录"><a href="#实例7：移动当前文件夹下的所有文件到上一级目录" class="headerlink" title="实例7：移动当前文件夹下的所有文件到上一级目录"></a>实例7：移动当前文件夹下的所有文件到上一级目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv * ../</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root 25 10-28 07:02 log1.txt</div><div class="line">-rw-r--r-- 1 root root 13 10-28 06:16 log2.txt</div><div class="line">[root@localhost test4]<span class="comment"># mv * ../</span></div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">[root@localhost test4]<span class="comment"># cd ..</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   25 10-28 07:02 log1.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log2.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 07:02 test4</div></pre></td></tr></table></figure>
<h3 id="实例8：把当前目录的一个子目录里的文件移动到另一个子目录里"><a href="#实例8：把当前目录的一个子目录里的文件移动到另一个子目录里" class="headerlink" title="实例8：把当前目录的一个子目录里的文件移动到另一个子目录里"></a>实例8：把当前目录的一个子目录里的文件移动到另一个子目录里</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv test3/*.txt test5</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong>   </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 4 root root 4096 10-28 07:02 test3</div><div class="line">drwxr-xr-x 3 root root 4096 10-25 17:56 test5</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   25 10-28 07:02 log1.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log2.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 07:02 test4</div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># mv test3/*.txt test5</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test5</span></div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   25 10-28 07:02 log1.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log2.txt</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1</div><div class="line">[root@localhost test5]<span class="comment"># 	cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3/</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root root 4096 10-28 06:21 logs</div><div class="line">drwxr-xr-x 2 root root 4096 10-28 07:02 test4</div><div class="line">[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例9：文件被覆盖前做简单备份，前面加参数-b"><a href="#实例9：文件被覆盖前做简单备份，前面加参数-b" class="headerlink" title="实例9：文件被覆盖前做简单备份，前面加参数-b"></a>实例9：文件被覆盖前做简单备份，前面加参数-b</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mv log1.txt -b log2.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   25 10-28 07:02 log1.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log2.txt</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1</div><div class="line">[root@localhost test5]<span class="comment"># mv log1.txt -b log2.txt</span></div><div class="line">mv：是否覆盖“log2.txt”? y</div><div class="line">[root@localhost test5]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   25 10-28 07:02 log2.txt</div><div class="line">-rw-r--r-- 1 root root   13 10-28 06:16 log2.txt~</div><div class="line">-rw-r--r-- 1 root root   29 10-28 06:05 test1.txt</div><div class="line">drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1</div><div class="line">[root@localhost test5]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;-b 不接受参数，mv会去读取环境变量VERSION_CONTROL来作为备份策略。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;–backup该选项指定如果目标文件存在时的动作，共有四种备份策略：   </p>
<ol>
<li>CONTROL=none或off : 不备份。    </li>
<li>CONTROL=numbered或t：数字编号的备份    </li>
<li>CONTROL=existing或nil：如果存在以数字编号的备份，则继续编号备份m+1…n：执行mv操作前已存在以数字编号的文件log2.txt.~1~，那么再次执行将产生log2.txt~2~，以次类推。如果之前没有以数字编号的文件，则使用下面讲到的简单备份。      </li>
<li>CONTROL=simple或never：使用简单备份：在被覆盖前进行了简单备份，简单备份只能有一份，再次被覆盖时，简单备份也会被覆盖。</li>
</ol>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/39. Linux 命令- date/" rel="next" title="Linux 命令- date">
                <i class="fa fa-chevron-left"></i> Linux 命令- date
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/10. Linux 命令- cat/" rel="prev" title="Linux 命令- cat">
                Linux 命令- cat <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1．命令格式："><span class="nav-number">1.</span> <span class="nav-text">1．命令格式：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2．命令功能："><span class="nav-number">2.</span> <span class="nav-text">2．命令功能：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3．命令参数："><span class="nav-number">3.</span> <span class="nav-text">3．命令参数：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4．命令实例："><span class="nav-number">4.</span> <span class="nav-text">4．命令实例：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：文件改名"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：文件改名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：移动文件"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：移动文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：将文件log1-txt-log2-txt-log3-txt移动到目录test3中。"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：将文件log1.txt,log2.txt,log3.txt移动到目录test3中。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖"><span class="nav-number">4.4.</span> <span class="nav-text">实例4：将文件file1改名为file2，如果file2已经存在，则询问是否覆盖</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：将文件file1改名为file2，即使file2存在，也是直接覆盖掉</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例6：目录的移动"><span class="nav-number">4.6.</span> <span class="nav-text">实例6：目录的移动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例7：移动当前文件夹下的所有文件到上一级目录"><span class="nav-number">4.7.</span> <span class="nav-text">实例7：移动当前文件夹下的所有文件到上一级目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例8：把当前目录的一个子目录里的文件移动到另一个子目录里"><span class="nav-number">4.8.</span> <span class="nav-text">实例8：把当前目录的一个子目录里的文件移动到另一个子目录里</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例9：文件被覆盖前做简单备份，前面加参数-b"><span class="nav-number">4.9.</span> <span class="nav-text">实例9：文件被覆盖前做简单备份，前面加参数-b</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
